use reqwest::Client;
use std::time::Duration;

pub async fn check_server(addr: &str, port: u16) -> u8 {
    let url = format!("http://{}:{}/api/config", addr, port);
    let client = Client::new();

    match tokio::time::timeout(Duration::from_secs(2), client.get(&url).send()).await {
        Ok(Ok(resp)) if resp.status().is_success() => 1, // 服务可达且返回 2xx
        _ => 0, // 服务不可达或超时或返回非 2xx
    }
}